package com.gt.admin.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.gt.admin.domain.CheckFlow;
import com.gt.admin.domain.FlowScheme;
import com.gt.admin.domain.apiVO.FlowSchemeVO;
import com.gt.admin.domain.vo.CheckVO;
import com.gt.admin.mapper.CheckFlowMapper;
import com.gt.admin.mapper.FlowSchemeMapper;
import com.gt.admin.service.IFlowSchemeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.ArrayList;
import java.util.List;

@Service
public class FlowSchemeServiceImpl extends ServiceImpl<FlowSchemeMapper, FlowScheme> implements IFlowSchemeService {
    @Autowired
    private FlowSchemeMapper flowSchemeMapper;
    @Autowired
    private CheckFlowMapper checkFlowMapper;

    /**
     * 发布随访方案
     * @param flowSchemeVO
     * @return
     */
    @Override
    @Transactional
    public boolean publishPlan(FlowSchemeVO flowSchemeVO) {
        boolean flag = save(flowSchemeVO);
        Long sickId = flowSchemeVO.getSickId();
        Long schemeId = flowSchemeVO.getSchemeId();
        List<CheckVO> checkVOList = flowSchemeVO.getCheckVOList();
        List<CheckFlow> checkFlowList = new ArrayList<>();
        for (CheckVO checkVO : checkVOList) {
            CheckFlow checkFlow = new CheckFlow();
            checkFlow.setCheckId(checkVO.getCheckId());
            checkFlow.setSchemeId(schemeId);
            checkFlow.setName(checkVO.getName());
            checkFlow.setSickId(sickId);
            checkFlowList.add(checkFlow);
        }
        if (checkFlowList.size()>0) {
            checkFlowMapper.insertBatchSomeColumn(checkFlowList);

        }
        return flag;
    }
}
